The present disclosure relates generally to memory buffer, and more specifically to a buffer mapping scheme involving pre-allocation of memory.
In a UNIX-based storage/server system, there are various applications and device drivers, each performing a specific task. For the applications, the operating system (OS)/kernel, and the hardware to communicate effectively, they often pass around a memory buffer. Typically, during these communications, an application communicates its application-level virtual address to the operating system/kernel. The memory buffer calls the driver using the application-level virtual address, and the driver maps the application-level virtual address to the operating system/kernel-level virtual address.
To make this translation easier, virtual and physical memory are divided into handy sized chunks called pages. In this paged model, a virtual address is composed of an offset and a virtual page frame number. Every time the processor encounters a virtual address, the processor extracts the offset and the virtual page frame number from the virtual address. The processor then translates the virtual page frame number into a physical page frame number to access the location at the correct offset into that physical page. To translate a virtual address into a physical address, the processor first works out the virtual address page frame number and the offset within that virtual page. The processor uses the virtual page frame number as an index into the process page table to retrieve its page table entry. If the page table entry at that offset is valid, the processor takes the physical page frame number from this entry. The tables the processor uses to convert the virtual page frame number into a physical frame number are called page tables.
Virtual address is calculated by adding an offset to the virtual page number. To further enforce protection, there are separate page tables for a user space application and kernel. In order to access a user space virtual address, kernel level software maps the user space address to kernel address space. This process involves creating kernel page table entries for the user space address.
As for the hardware, the connection between the OS/kernel and the hardware occurs by way of direct memory access (DMA). By using DMA, a hardware device can transfer data from/to computer's main memory without involving CPU. For DMA to work, memory buffers are frequently mapped to an address range that is visible to the hardware device. This address range is called IO virtual address. Depending on the architecture, this may involve setting up translation between IO virtual address and physical address of computer main memory. Usually, this happens using IOMMU hardware. On some architectures, IO virtual address might be the same as the physical address of the computer main memory.
The above-described mapping scheme puts a heavy burden on the OS/kernel, which is required to first translate the application-level virtual address into OS-level virtual address by setting up page table entries. Similarly, DMA mapping should be established for every DMA transfer. A more efficient method for the OS, applications, and hardware to communicate is desired.